// map.js
// 加载百度地图
export function LoadBaiduMapScript() {                   
    const BMap_URL = "https://api.map.baidu.com/api?v=3.0&ak=aCLumclGBVns0H0j4qwmeVgmjtw1PgkN&callback=onBMapCallback";
    return new Promise((resolve, _reject) => {
        // 如果已加载直接返回
        const win: any = window
        const BMap = win.BMap
        if(typeof BMap !== "undefined") {
            resolve(BMap);
            return true;
        }
        // 百度地图异步加载回调处理
        win.onBMapCallback = function () {
            console.log("百度地图脚本初始化成功...");
            resolve(win.BMap);
        };
        // 插入script脚本
        const scriptNode = document.createElement("script");
        scriptNode.setAttribute("type", "text/javascript");
        scriptNode.setAttribute("src", BMap_URL);
        document.body.appendChild(scriptNode);
    });
  }